package mofei.concurrent.utils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author mofei@staff.weibo.com
 * @date 2019/2/27 6:21 PM
 */
public class DemoHolder {


    private static List<Long> ageList=new ArrayList<>();
    private static AtomicLong runNums=new AtomicLong(1);
    public static CountDownLatch countDownLatch=new CountDownLatch(100);
    static{
        ageList.add(1L);
    }

    private static Lock lock=new ReentrantLock();
    public static void incrementAge(){
        try{
            lock.lock();
            System.out.println("incrementAge");
            long now=ageList.get(0);
            ageList.set(0,++now) ;
            runNums.incrementAndGet();
        }finally {
            countDownLatch.countDown();
            lock.unlock();
        }

    }


    public static boolean isRight(){
        return ageList.get(0)==runNums.longValue();
    }


}
